<template>
  <div style="margin-left: 12%;margin-top: 2%">
    <el-row style="height: 750px;">
      <div v-for="item in books.slice((currentPage-1)*pageSize,currentPage*pageSize)" @click="showT(item)">
        <el-card :id="item.bookId" style="width: 280px;height: 330px;float: left;margin-right: 15px" class="book"
                 bodyStyle="padding:10px" shadow="hover">
          <div class="cover">
            <img :src="'https://images.weserv.nl/?url='+item.img" onerror="this.src='static/error.jpg'" alt="封面">
          </div>
          <div class="title">
            <a href="">{{item.bookName}}</a>
          </div>
          <div class="author">{{item.author}}</div>
        </el-card>
      </div>
    </el-row>
    <el-row style="margin-top: -2%;margin-left: -8%">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="books.length"
        layout="total, prev, pager, next, jumper">
      </el-pagination>
    </el-row>
  </div>
</template>

<script>
  export default {
    name: 'Books',
    data() {
      return {
        books: [
          {
            bookId: '',
            typeId: '',
            img: '',
            bookName: '',
            author: '',
            publisher: '',
            price: '',
            summary: '',
            bnumber: ''
          },
        ],
        currentPage: 1,
        pageSize: 10,
        index: '',
      }
    },
    created() {
      let _this=this;
      _this.index=this.$route.query.index;
      if(_this.index==25){
          _this.$axios.get('/library/books')
            .then(resp => {
              if (resp.data.code == 200) {
                _this.books = resp.data.data;
              }
            });
      }
      else if(_this.index>=1&&_this.index<=20){
        _this.$axios.post('/library/selectBT/'+_this.index)
          .then(resp=>{
            if(resp.data.code==200){
              _this.books=resp.data.data;
            }
          })
      }
      else{
        _this.$axios.post('/library/selectBN/'+_this.index)
          .then(resp => {
            if (resp.data.code == 200) {
              _this.books = resp.data.data;
            }
          })
      }
    },
    methods: {
      showT(e) {
        this.$router.push({path:'/commodity',query:{book:e}});
      },
      handleCurrentChange: function (currentPage) {
        this.currentPage = currentPage;
      },
    }
  }
</script>
<style scoped>

  .cover {
    width: 180px;
    height: 212px;
    margin-bottom: 7px;
    overflow: hidden;
    cursor: pointer;
  }

  img {
    width: 155px;
    height: 212px;
    /*margin: 0 auto;*/
  }

  .title {
    width: 200px;
    font-size: 13px;
    text-align: center;
  }

  .author {
    text-align: center;
    color: #333;
    width: 200px;
    font-size: 13px;
    margin-bottom: 6px;
  }

  .abstract {
    display: block;
    line-height: 17px;
  }

  .el-icon-delete {
    cursor: pointer;
    float: right;
  }

  .switch {
    display: flex;
    position: absolute;
    left: 780px;
    top: 25px;
  }

  a {
    text-decoration: none;
  }

  a:link, a:visited, a:focus {
    color: #3377aa;
  }

</style>


